---
title: Agentic RAG with LightRAG
---

This example demonstrates how to implement Agentic RAG using LightRAG as the vector database, with support for PDF documents, Wikipedia content, and web URLs.

## Code

```python agentic_rag_with_lightrag.py
import asyncio
from os import getenv

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.wikipedia_reader import WikipediaReader
from agno.vectordb.lightrag import LightRag

vector_db = LightRag(
    api_key=getenv("LIGHTRAG_API_KEY"),
)

knowledge = Knowledge(
    name="My Pinecone Knowledge Base",
    description="This is a knowledge base that uses a Pinecone Vector DB",
    vector_db=vector_db,
)


asyncio.run(
    knowledge.add_content(
        name="Recipes",
        path="cookbook/knowledge/testing_resources/cv_1.pdf",
        metadata={"doc_type": "recipe_book"},
    )
)

asyncio.run(
    knowledge.add_content(
        name="Recipes",
        topics=["Manchester United"],
        reader=WikipediaReader(),
    )
)

asyncio.run(
    knowledge.add_content(
        name="Recipes",
        url="https://en.wikipedia.org/wiki/Manchester_United_F.C.",
    )
)


agent = Agent(
    knowledge=knowledge,
    search_knowledge=True,
    read_chat_history=False,
)


asyncio.run(
    agent.aprint_response("What skills does Jordan Mitchell have?", markdown=True)
)

asyncio.run(
    agent.aprint_response(
        "In what year did Manchester United change their name?", markdown=True
    )
)
```

## Usage

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install libraries">
    ```bash
    pip install -U agno lightrag
    ```
  </Step>

  <Step title="Export your API keys">
  <CodeGroup>

  ```bash Mac/Linux
    export OPENAI_API_KEY="your_openai_api_key_here"
    export LIGHTRAG_API_KEY="your_lightrag_api_key_here"
  ```

  ```bash Windows
    $Env:OPENAI_API_KEY="your_openai_api_key_here"
    $Env:LIGHTRAG_API_KEY="your_lightrag_api_key_here"
  ```
  </CodeGroup> 
</Step>

  <Step title="Create a Python file">
    Create a Python file and add the above code.
    ```bash
    touch agentic_rag_with_lightrag.py
    ```
  </Step>

  <Step title="Run Agent">
    <CodeGroup>
    ```bash Mac
    python agentic_rag_with_lightrag.py
    ```
    
    ```bash Windows
    python agentic_rag_with_lightrag.py
    ```
    </CodeGroup>
  </Step>

  <Step title="Find All Cookbooks">
    Explore all the available cookbooks in the Agno repository. Click the link below to view the code on GitHub:

    <Link href="https://github.com/agno-agi/agno/tree/main/cookbook/agents/agentic_search" target="_blank">
      Agno Cookbooks on GitHub
    </Link>
  </Step>
</Steps>